home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Windows / SaveGraph < prev   
Text File  |  1996-01-29  |  4KB  |  173 lines

  1. // SaveGraph 1.1
  2. //
  3. //  Creates an Igor Text file that will be able to recreate the target graph (including the data)
  4. //  in another experiment.
  5. //
  6. // To use, simply bring the graph you wish to save to the front and select "Save Graph"
  7. // from the Macros menu.  You will be presented with a save dialog. 
  8. // Later, in another experiment, you can use the "Load Igor Text..." item from the Data menu 
  9. // to load the file. The data will be loaded and the graph will be regenerated. 
  10. //
  11. // "Save Graph" makes an Igor Text file that, when later loaded,  will load the data into a data folder
  12. // of the same name as your graph.  If there are conflicts in the wave names, subfolders called
  13. // data1 etc will be created for any subsequent waves.
  14. //
  15. // No data folders or waves are created by the Save Graph macros in the experiment where
  16. // the graph was first created.  All new folders and waves are generated by loading the Igor
  17. // Text file that recreates the graph.  The new folders and waves are in the destination experiment.
  18. //
  19. // NOTE:  The data folder hierarchy from the original experiment is not preserved by Save Graph.
  20. //
  21. // Version 1.1 differs from the first version as follows:
  22. //    Supports Igor 3.0's Data Folders, liberal wave names
  23. //    Supports contour and image graphs.
  24.  
  25. #pragma rtglobals=1
  26.  
  27.  
  28. Menu "Macros"
  29.     "Save Graph", DoSaveGraphToFile()
  30. end
  31.  
  32. Function DoSaveGraphToFile()
  33.     
  34.     Variable numWaves
  35.     Variable refnum
  36.     Variable i
  37.     Variable pos0, pos1
  38.     Variable FolderLevel=1
  39.  
  40.     String TopFolder, FolderName
  41.     String WinRecStr
  42.     String fileName
  43.     String wname=  WinName(0,1)
  44.     
  45.     if( strlen(wname) == 0 )
  46.         DoAlert 0,"No graph!"
  47.         return 0
  48.     else
  49.         DoWindow/F $wname
  50.     endif
  51.     
  52.     TopFolder= wname
  53.     
  54.     
  55.     GetWindow kwTopWin, wavelist
  56.     Wave/T wlist=W_WaveList
  57.     numWaves = DimSize(wlist, 0)
  58.     
  59.     Redimension/N=(-1,5) wlist
  60.     
  61.     MakeUniqueFolders(wlist, "data")
  62.     
  63.     Open/D refnum as wname
  64.     filename=S_filename
  65.     
  66.     if (strlen(filename) == 0)
  67.         DoAlert 0, "You cancelled the Save Graph operation"
  68.         KillWaves/Z wlist
  69.         return 0
  70.     endif
  71.     
  72.     Open refnum as filename
  73.     fprintf refnum, "%s", "IGOR\r"
  74.     fprintf refnum, "%s", "X NewDataFolder/S/O "+TopFolder+"\r"
  75.     close refnum
  76.     
  77.     i = 0
  78.     do
  79.         if (strlen(wlist[i][3]) != 0)
  80.             Open/A refnum as filename
  81.             if (FolderLevel > 1)
  82.                 fprintf refnum, "%s", "X SetDataFolder ::\r"
  83.             endif
  84.             fprintf refnum, "%s", "X NewDataFolder/S "+wlist[i][3]+"\r"
  85.             FolderLevel=2
  86.             close refnum
  87.         endif
  88.         Execute "Save/A/T "+wlist[i][1]+" as \""+FileName+"\""
  89.  
  90.         i += 1
  91.     while (i < numWaves)
  92.  
  93.     if (FolderLevel > 1)
  94.         Open/A refnum as filename
  95.         fprintf refnum, "%s", "X SetDataFolder ::\r"
  96.         close refnum
  97.     endif
  98.  
  99.     WinRecStr = WinRecreation(wname, 2)
  100.     i = 0
  101.     FolderName = ""
  102.     do
  103.         pos0=0
  104.         if (strlen(wlist[i][3]) != 0)
  105.             FolderName = ":"+wlist[i][3]+":"
  106.         endif
  107.         do
  108.             pos0=strsearch(WinRecStr, wlist[i][2], pos0+1)
  109.             if (pos0 < 0)
  110.                 break
  111.             endif
  112.             WinRecStr[pos0,pos0+strlen(wlist[i][2])-1] = FolderName+PossiblyQuoteName(wlist[i][0])
  113.     
  114.         while (1)
  115.         i += 1
  116.     while (i<numWaves)
  117.     
  118.     Open/A refnum as filename
  119.     
  120.     pos0= strsearch(WinRecStr, "\r", 0)
  121.     pos0= strsearch(WinRecStr, "\r", pos0+1)+1
  122.     fprintf refnum,"X Preferences 0\r"
  123.     do
  124.         pos1= strsearch(WinRecStr, "\r", pos0)
  125.         if( (pos1 == -1) %| (cmpstr(WinRecStr[pos0,pos0+2],"End") == 0 ) )
  126.             break
  127.         endif
  128.         fprintf refnum,"X%s%s",WinRecStr[pos0,pos1-1],";DelayUpdate\r"
  129.         pos0= pos1+1
  130.     while(1)
  131.     
  132.     fprintf refnum, "%s", "X SetDataFolder ::\r"
  133.     fprintf refnum,"X Preferences 1\r"
  134.     fprintf refnum,"X KillStrings S_waveNames\r"
  135.     close refnum
  136.     
  137.     KillWaves/Z wlist
  138.     return 0
  139.     
  140. end
  141.  
  142. Function MakeUniqueFolders(wlist, FBaseName)
  143.     Wave/T wlist
  144.     String FBaseName
  145.     
  146.     Variable i,j, endi = DimSize(wlist, 0), startj = 0
  147.     Variable FolderNum = 0
  148.     
  149.     wlist[0][3] = ""
  150.     
  151.     i = 1
  152.     do
  153.     
  154.         j = startj
  155.         do
  156.             if (cmpstr(wlist[i][0], wlist[j][0]) == 0)
  157.                 FolderNum +=1
  158.                 wlist[i][3] = FBaseName+num2istr(FolderNum)
  159.                 startj = i
  160.                 break
  161.             endif
  162.         
  163.             j += 1
  164.         while (j < i)
  165.     
  166.     
  167.         i += 1
  168.     while (i < endi)
  169. end
  170.     
  171.     
  172.  
  173.